package com.beyondcreative.stylebean;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.Window;
import android.view.WindowManager;

import com.beyondcreative.fragment.BeanHatchFragment;
import com.beyondcreative.fragment.StorageFragment;
import com.beyondcreative.fragment.TreeFragment;
import com.viewpagerindicator.TabPageIndicator;

public class MainActivity extends FragmentActivity {
	int intro = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.activity_main);
		intro();
		FragmentPagerAdapter adapter = new GoogleMusicAdapter(
				getSupportFragmentManager());

		ViewPager pager = (ViewPager) findViewById(R.id.pager);
		pager.setAdapter(adapter);
		TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.indicator);
		indicator.setViewPager(pager);
		indicator.setCurrentItem(1);

	}

	private void intro() {
		Intent intent = getIntent();
		if (intent != null) {
			intro = intent.getIntExtra("intro", intro);
		}
		if (intro <= 0) {
			startActivity(new Intent(this, IntroActivity.class));
		}
	}

	class GoogleMusicAdapter extends FragmentPagerAdapter {
		String[] CONTENT = new String[] { "BeanHatch", "BeanTree", "Storage" };

		public GoogleMusicAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int position) {
			if(position==0){
				return BeanHatchFragment.newInstance(CONTENT[position]);	
			}
			else if(position==1){
				return TreeFragment.newInstance(CONTENT[position]);
			}
			else
			{
				return StorageFragment.newInstance(CONTENT[position]);
			}
			
		}

		@Override
		public CharSequence getPageTitle(int position) {
			return CONTENT[position % CONTENT.length].toUpperCase();
		}

		@Override
		public int getCount() {
			return CONTENT.length;
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		return true;
	}

}
